<?php
	if($_COOKIE['user_id']!='admin')
		Header("location:main.php");
	require_once('start_session.php');
	//setcookie('user_id', 'famous');
	require_once('header.php');
	require_once('db_connect.php');
	require_once('global_vars.php');
	//require_once('search_bar.php');
	require_once('admin_menu.php');
?>

<script type="text/javascript">
function getXMLHttpRequest(){
					if(window.XMLHttpRequest){
						return new XMLHttpRequest();
					}else if(window.ActiveXObject){
						try{
								return new ActiveXObject("Msxml2.XMLHTTP");
							}catch(e){
								try{
										return ActiveXObject("Microsoft.XMLHTTP");
									}catch(e){
										return null;
									}
							}
						}
					else{
						return null;
					}
					
				}
				var xhr = getXMLHttpRequest();
								
				// 객체 생성하고 함수 생성
				function Select_date()
				{
					var val = document.getElementById('year').value;
					var val2 = document.getElementById('month').value;
					var val3 = document.getElementById('day').value;						
					var url = "request_graph.php?year="+val+"&month="+val2+"&day="+val3;
					xhr.open("Get",url,true);
					xhr.onreadystatechange = callback;
					xhr.send();					
				}
				function callback()
				{					
					if (xhr.readyState == 4)
					{							
						if (xhr.status == 200)
						{								
							var txt = xhr.responseText;							
							document.getElementById('graph').innerHTML = txt;
							//innerHTML
						}
					}
				}
				
</script>
<div id="statistic_info">
<h3>접속자 통계 정보</h3>
<table>
<thead>
	
	<center><label>열람일자선택 :</label> <select id=year name=year onchange=Select_date()>
	<option value="">
	<?	
		$sql="SELECT DISTINCT DATE_FORMAT( TIME,  '%Y' ) AS YEAR FROM  `connect_log` WHERE 1";
		$result=mysqli_query($conn,$sql);
		while($row=mysqli_fetch_array($result))
		{
			echo "<option value=$row[YEAR]>$row[YEAR]";
		}
		echo "</select>";		
			
	?>년
	<select id=month name=month onchange=Select_date()>
	<option value="">
	<?
	  for($i=1; $i<13; $i++)
		echo "<option value=$i>$i";
	?>
	</select>월
	<select id=day name=day onchange=Select_date()>
	<option value"">
	<?
		for($i=1; $i<32; $i++)
		echo "<option value=$i>$i";
	?>
	</select>일</center>
	
	<div id=graph></div>	
</thead>
</table>
</div>
<div id="footer">
</div>
</div>
</body>
</html>